package club.justwill.single.model;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class JsonResponse implements Serializable{
	public static final String STATUS_SUCCESS = "ok";
	public static final String STATUS_FAILED = "fail";

	@JsonProperty("ERROR")
	private Map<Integer, String> errors;

	@JsonProperty("WARN")
	private Map<Integer, String> warns;

	@JsonProperty("INFO")
	private Map<Integer, String> infos;

	private String status = STATUS_SUCCESS;

	private Object data;

	public JsonResponse() {
		errors = new HashMap<Integer, String>();
		warns = new HashMap<Integer, String>();
		infos = new HashMap<Integer, String>();
	}

	public boolean isSuccessful() {
		return STATUS_SUCCESS.equals(getStatus());
	}

	public void setSuccessful() {
		setStatus(STATUS_SUCCESS);
	}

	public void setFailed() {
		setStatus(STATUS_FAILED);
	}

	public Map<Integer, String> getErrors() {
		if (errors == null) {
			errors = new HashMap<Integer, String>();
		}
		return errors;
	}

	public void setErrors(Map<Integer, String> errors) {
		this.errors = errors;
	}

	public Map<Integer, String> getWarns() {
		if (warns == null) {
			warns = new HashMap<Integer, String>();
		}
		return warns;
	}
	//generated getters and setters

	public void setWarns(Map<Integer, String> warns) {
		this.warns = warns;
	}

	public Map<Integer, String> getInfos() {
		if (infos == null) {
			infos = new HashMap<Integer, String>();
		}
		return infos;
	}

	public void setInfos(Map<Integer, String> infos) {
		this.infos = infos;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}
}
